package com.example.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.bean.User;
import com.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class TableController {


    @Autowired
    UserService userService;

    @GetMapping("/basic_table")
    public String basic_table() {
        return "table/basic_table";
    }

    @GetMapping("/dynamic_table")
    public String dynamic_table() {
        return "table/dynamic_table";
    }

    @GetMapping("/responsive_table")
    public String responsive_table() {
        return "table/responsive_table";
    }

    @GetMapping("/editable_table")
    public String editable_table(@RequestParam(value="pn", defaultValue = "1") Integer pn, Model model) {

//        List<User> list = userService.list();
//        model.addAttribute("user", list);
//        return "table/editable_table";

        //构造分页参数
        Page<User> page = new Page<>(pn, 2);
        //分页查询
        Page<User> userPage = userService.page(page, null);

//        List<User> records = userPage.getRecords();


        System.out.println(userPage.getSize());
        System.out.println(userPage.getRecords());
        System.out.println(userPage.getCurrent());

        model.addAttribute("userPage", userPage);
        return "table/editable_table";
    }

}
